package com.yizisu.playerlibrary.view.video_view.view

import android.content.Context
import android.util.AttributeSet
import android.widget.Toast
import androidx.appcompat.widget.AppCompatImageView
import com.yizisu.playerlibrary.R
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerConfig
import com.yizisu.playerlibrary.view.video_view.helper.IPlayerHelper

/**
 * 播放下一个
 */
open class PlayerNextView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : AppCompatImageView(
    context,
    attrs,
    defStyleAttr
), IPlayerHelper {

    override fun onAttachPlayerConfig(playerConfig: IPlayerConfig) {
        super.onAttachPlayerConfig(playerConfig)
        setOnClickListener {
            playerConfig.player?.let { player ->
                if (player.canPlayNext()) {
                    player.next()
                } else {
                    Toast.makeText(context, "当前已经最后一个播放",Toast.LENGTH_LONG).show()
                }
            }
        }
        if (drawable == null) {
            setImageResource(R.drawable.exo_icon_next)
        }
    }
}